<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Admin\Traits\AdminTrait;
use App\Http\Requests\Admin\BaseRequest;
use Illuminate\Support\Facades\Log;

class DicionaryController extends AdminController
{
    use AdminTrait;

    public function __construct()
    {
        parent::__construct();
    }


    /**
     * @desc 字典数据
     */
    public function info(BaseRequest $request)
    {
        try {
            $params = $request->all();

            if (!isset($params['type']))
                return $this->error(['类型参数不能为空', 40001]);

            if (!isset(self::$config[$params['type']]))
                return $this->error(['该类型字典未配置', 40001]);

            return $this->success(self::$config[$params['type']]);
        } catch (\Exception $e) {
            Log::error($request->route()->uri, ['errMsg' => $e->getMessage(), 'params' => $request->all()]);
            return $this->error([$e->getMessage(), $e->getCode()]);
        }
    }

}
